<?php
	include"common.php";
	session_start();
	error_reporting(0);
	if($_SESSION['logInCheck']!=1){
		header('Location: index.php?loginInfo=false');
	}
	$userLink = $_SESSION['userLink'];
	if($userLink!="hrpage.php"){
		echo "Sorry, You have no right to visit this page!!";
		exit;
	}
	$ID = $_SESSION['id'];
	$supervisor = $_SESSION['supervisor'];
	$userName = $_SESSION['userFname'];
	$role = $_SESSION['role'];
	$userLink = $_SESSION['userLink'];
	$userSql = "SELECT * FROM user WHERE e_id = '$supervisor'";
	$userSqlQuery = mysql_query($userSql);
	$userSqlQueryResult = mysql_fetch_assoc($userSqlQuery);	
	$supervisorFname = $userSqlQueryResult['f_name'];
	$supervisorLname = $userSqlQueryResult['l_name'];
	$timezone_offset = 6; // for getting local time offset hrs
	$systemDate = gmdate('y-m-d', time()+$timezone_offset*60*60);
	$checkAlreadySubmitted = "SELECT * FROM reason_for_late WHERE e_id='$ID' and date='$systemDate' and submit='1'";
	$checkAlreadySubmittedQuery = mysql_query($checkAlreadySubmitted);
	$checkAlreadySubmittedRows = mysql_num_rows($checkAlreadySubmittedQuery);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="index.css" type="text/css" />
<link rel="icon" type="image/ico" href="images/favicon.ico"></link> 
<link rel="shortcut icon" href="images/favicon.ico"></link>
<link rel="stylesheet" type="text/css" href="jquery.alerts.css" />
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery-ui.js" type="text/javascript"></script>
<script src="jquery.ui.draggable" type="text/javascript"></script>
<script src="jquery.alerts.js" type="text/javascript"></script>
<script src="curvycorners.src.js" type="text/javascript"></script>
<script src="login.js" type="text/javascript"></script>
<title><?php echo "Welcome to ".$userFname." ".$userLname; ?></title>
</head>

<body>
<div class="main_div_other">
	<p><img src="images/creato_logo.jpg" /></p>
    <p id="creatobd">www.creatobd.com</p>
    <p id="date"><script>document.write(new_month+" "+new_date+", "+old_date.getFullYear()+" || "+new_day);</script></p>
    <div class="other_page_icons">
    	<div class="new_notification">
        	<img src="images/arrow_up.JPG" /><?php if ($notification >0){?><p>You have<?php echo " ".$notification." ";?>new notification</p><?php }?>
        </div><!--end of new_notification-->
    	<ul>
        	<a href="hrpage.php"><li><div id="home"></div><p>home</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="hr_employee.php"><li><div id="employee"></div><p>employee</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="hr_onduty.php"><li><div id="onduty"></div><p>on duty</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="hr_attendance.php"><li><div id="attendance"></div><p>attendance</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="hr_leave.php"><li><div id="leave"></div><p>leave</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="hr_notification.php"><li><div id="notification"></div><p>notification</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="hr_black_box_message.php"><li><div id="blackbox"></div><p>black box</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="ceo_notice.php"><li><div id="hrpolicy"></div><p>hr policy</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
            <a href="index.php"><li><div id="logout"></div><p>log out</p><p class="present_class"><img src="images/arrow_up.JPG" /></p></li></a>
        </ul>
    </div><!-- end of other_page_icons-->
    
</div><!-- end of main_div_other-->
<div class="othrpage_1">
    <p>view as: <a href="#">today</a> | <a href="#">week</a> | <a href="#">month</a> | <a href="#">late</a>
     | <a href="#">on time</a> | <a href="#">by name</a></p>
</div><!-- end of othrpage_1-->
<div class="human_portal">
  		<p>creato human resourse portal</p>
</div><!-- end of human_portal-->
<form method="post" action="hrlatereasonapprove.php">
			<table cellpadding="0" 

cellspacing="0" class="apply4leave_table">
				<tr valign="top">
					<td>Employee 

Id</td>
					<td><input 

type="text" name="id" value="<?php echo $ID?>" 

readonly=""/></td>
				</tr>
				<tr>
					<td>Reason</td>
					<td><textarea 

rows="6" name="reason"></textarea></td>
				</tr>
				<tr><td><input 

type="hidden" name="check" value="1"/><input 

type="submit" value="submit" /></td></tr>
			</table>
		</form>
        <?php
			$permission = $_POST['check']; 
			if

($checkAlreadySubmittedRows>0){
				echo "You already 

submitted";
			}
			
		?>
</body>
</html>

	<?php
	$permission = $_POST['check'];	
	if($permission==1 && $checkAlreadySubmittedRows!=1){
		$sms = $_POST['reason'];
		$insertLateInfo = "UPDATE reason_for_late SET submit=1, reason='$sms' WHERE e_id='$ID'";
		mysql_query($insertLateInfo);	
		$notifGoesToBoss = "SELECT * FROM user WHERE e_id='$ID'";
		$notifGoesToBossQuery = mysql_query($notifGoesToBoss);
		$notifGoesToBossFetchArray = mysql_fetch_array($notifGoesToBossQuery);
		$whoTheAdmin = $notifGoesToBossFetchArray['supervisor'];
		$collectDataFromReasonForLate = "SELECT * FROM reason_for_late WHERE e_id='$ID'";
		$collectDataFromReasonForLateQuery = mysql_query($collectDataFromReasonForLate);
		$collectDataFromReasonForLateFetchArray =  mysql_fetch_array($collectDataFromReasonForLateQuery);
		$dataFromReasonFromLateRefferenceId = $collectDataFromReasonForLateFetchArray['id'];
		$insertIntoNotificationTable = "INSERT INTO notification(reference_id,e_id,supervisor,Type,Reason,Status) VALUES('$dataFromReasonFromLateRefferenceId','$ID','$whoTheAdmin','reason_for_late','$sms','2')";
		$insertIntoNotificationTableQuery = mysql_query($insertIntoNotificationTable);
		$warning_update = "UPDATE user SET warning='6' WHERE e_id='$id'";
		$warning_updateQuery = mysql_query($warning_update);
		echo "Successfully submitted";		
	}
	//echo <pre>;
	//print_r('$insertIntoNotificationTableQuery');
?>